﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALinq.Mapping
{
    /// <summary>
    /// </summary>
    class ModelMappingVisitor
    {
        public void Visit(ModelMapping modelMapping)
        {
           switch(modelMapping.MappingType)
           {
               case ModelMappingType.Database:
                   VisitDatabase((DatabaseMapping) modelMapping);
                   break;
               case ModelMappingType.Table:
                   VisitTable((TableMapping) modelMapping);
                   break;
               case ModelMappingType.Type:
                   VisitType((TypeMapping) modelMapping);
                   break;
               case ModelMappingType.Column:
                   VisitType((TypeMapping) modelMapping);
                   break;
               case ModelMappingType.Association:
                   VisitAssociation((AssociationMapping) modelMapping);
                   break;
               default:
                   throw Error.UnknowModelMappingType(modelMapping.MappingType);
           }
        }

        public virtual void VisitDatabase(DatabaseMapping databaseMapping)
        {
            foreach (var table in databaseMapping.Tables)
                VisitTable(table);
        }

        public virtual void VisitTable(TableMapping tableMapping)
        {
            VisitType(tableMapping.RowType);
        }

        public virtual void VisitType(TypeMapping typeMapping)
        {
            foreach (var column in typeMapping.Columns)
                VisitColumn(column);

            foreach (var association in typeMapping.Associations)
                VisitAssociation(association);

            foreach (var type in typeMapping.DerivedTypes)
                VisitType(type);
        }

        public virtual void VisitAssociation(AssociationMapping association)
        {
            
        }

        public virtual void VisitColumn(ColumnMapping columnMapping)
        {
            
        }
    }
}
